Socket Connection
In order to connect the user and the doctor
there should be a channel that reflects the status update of the consultation,
So we have the TBISocket
class to deal with the socket
Socket Attributes
For initiating the socket, you need the socketChannel
and socketKey
from the Consultation
object
Here is the consultation data once the consultation is created:
{
consultationId: 123,
socketChannel: "channel"
socketKey: "key"
# ... Other Consultation properties
}
TBISocket initiateSocket
Using initiateSocket
method the connection will be established and subscribed.
You only need following:
appKey
This is thesocketKey
from ConsultationchannelName
This is thesocketChannel
from ConsultationonEvent
This is a function to handle the events and data from socket connection
Check the code below:
import AltibbiTelehealth
// get appKey and channelName from the created consultation info
// declare a function 'onEvent' to get the events from the socket
func onEvent(name: String, data: String?) {
if let data = data {
if data == "accepted" {
// This indicates that doctor accepted the consultation but still not started
} else if data == "in_progress" {
// This indicates that consultation started
}
}
}
TBISocket.initiateSocket(
appKey: appKey,
channelName: channelName,
onEvent: onEvent
)
Next Step (Move to Consultation)
From the onEvent
function the data returned will be the status that indicates the acceptance and starting of the consultation
During the socket connection, you can use getConsultationInfo
to check if the Consultation Config
is ready
For chat
consultation the data will include the chatConfig
object
For voip
consultations the data will include the voipConfig
object
For video
consultations the data will include the videoConfig
object
Config Struct
struct ChatConfig {
id: Int?
consultationId: Int?
groupId: String?
chatUserId: String?
appId: String?
chatUserToken: String?
}
# For Both, voipConfig and videoConfig
struct VoipConfig {
id: Int?
consultationId: Int?
apiKey: String?
callId: String?
token: String?
}